package top.infopub.mgr.cap.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.infopub.mgr.cap.dao.CreditBalanceManagementDao;
import top.infopub.mgr.cap.domain.CreditBalanceManagementDomain;
import top.infopub.mgr.cap.service.CreditBalanceManagementService;
import top.infopub.mgr.cap.vo.CreditBalanceManagementVo;
import top.infopub.model.cap.CreditBalanceManagement;
import top.infopub.security.util.SessionUserUtils;
import top.infopub.security.vo.AuthorizationVO;
import top.infopub.tdp.sys.service.CodeGeneratorConfigService;
import top.infopub.util.IdFactory;

import java.util.List;

@Service
public class CreditBalanceManagementServiceImpl implements CreditBalanceManagementService {
    @Autowired
    private CreditBalanceManagementDao creditBalanceManagementDao;
    @Autowired
    private CodeGeneratorConfigService codeGeneratorConfigService;

    @Override
    public Page<CreditBalanceManagementDomain> selectByDomainWhere(Page<CreditBalanceManagementDomain> page, CreditBalanceManagementVo creditBalanceManagementVo) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<CreditBalanceManagementDomain>)creditBalanceManagementDao.selectByDomainWhere(creditBalanceManagementVo);
    }

    @Override
    @Transactional(rollbackFor =Exception.class )
    public int add(CreditBalanceManagement creditBalanceManagement) {
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        String id = IdFactory.getUUIDUpper();
        creditBalanceManagement.setId(id);
        creditBalanceManagement.setAddBy(vo.getId());
        creditBalanceManagement.setAddTime(top.infopub.mgr.util.DateUtils.getCurrentDateTime());
        String code = codeGeneratorConfigService.generatorCode("adm_borrow_record");
        creditBalanceManagement.setCodes(code);
        return creditBalanceManagementDao.add(creditBalanceManagement);
    }

    @Override
    public List<String> selectBankName() {
        return creditBalanceManagementDao.selectBankName();
    }
}
